home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / UUPC11QS.ARJ / DCPSTATS.C < prev    next >
C/C++ Source or Header  |  1991-11-24  |  5KB  |  146 lines

  1. /*--------------------------------------------------------------------*/
  2. /*    File transfer information for UUPC/extended                     */
  3. /*                                                                    */
  4. /*    Copyright (c) 1991, Andrew H. Derbyshire                        */
  5. /*--------------------------------------------------------------------*/
  6.  
  7. /*--------------------------------------------------------------------*/
  8. /*                       standard include files                       */
  9. /*--------------------------------------------------------------------*/
  10.  
  11. #include <stdio.h>
  12. #include <string.h>
  13. #include <time.h>
  14. #include <stdlib.h>
  15.  
  16. /*--------------------------------------------------------------------*/
  17. /*                    UUPC/extended include files                     */
  18. /*--------------------------------------------------------------------*/
  19.  
  20. #include "lib.h"
  21. #include "dcp.h"
  22. #include "dcpstats.h"
  23. #include "hlib.h"
  24. #include "hostable.h"
  25. #include "hostatus.h"
  26. #include "security.h"
  27. #include "timestmp.h"
  28.  
  29. /*--------------------------------------------------------------------*/
  30. /*                          Global variables                          */
  31. /*--------------------------------------------------------------------*/
  32.  
  33. currentfile();
  34.  
  35. /*--------------------------------------------------------------------*/
  36. /*    d c s t a t s                                                   */
  37. /*                                                                    */
  38. /*    Report transmission information for a connection                */
  39. /*--------------------------------------------------------------------*/
  40.  
  41. void dcstats(void)
  42. {
  43.    if (hostp == BADHOST)
  44.    {
  45.       printmsg(0,"dcstats: host structure pointer is NULL");
  46.       panic();
  47.    }
  48.  
  49.    if (!equal(rmtname , hostp->hostname))
  50.       return;
  51.  
  52.    if ((remote_stats.lconnect > 0))
  53.    {
  54.       time_t connected;
  55.       unsigned long bytes;
  56.       unsigned long bps;
  57.  
  58.       connected = time(NULL) - remote_stats.lconnect;
  59.       remote_stats.connect += connected;
  60.       bytes = remote_stats.bsent + remote_stats.breceived;
  61.       if ( connected > 0 )
  62.          bps = bytes / (long unsigned) connected;
  63.       else
  64.          bps = 0;
  65.       printmsg(0,"%ld files sent, %ld files received, \
  66. %ld bytes sent, %ld bytes received",
  67.             remote_stats.fsent, remote_stats.freceived ,
  68.             remote_stats.bsent, remote_stats.breceived);
  69.       printmsg(0, "%ld packets transferred, %ld errors, \
  70. connection time %ld:%02ld, %ld bytes/second",
  71.             (long) remote_stats.packets,
  72.             (long) remote_stats.errors,
  73.             (long) connected / 60L, (long) connected % 60L, bps);
  74.  
  75.    } /*if */
  76.    else
  77.       printmsg(0,"Unable to print information for host %s (%s)",rmtname,
  78.             hostp->hostname);
  79.  
  80.    if (remote_stats.lconnect > hostp->hstats->lconnect)
  81.       hostp->hstats->lconnect = remote_stats.lconnect;
  82.    if (remote_stats.ltime > hostp->hstats->ltime)
  83.       hostp->hstats->lconnect = remote_stats.lconnect;
  84.  
  85.    hostp->hstats->connect   += remote_stats.connect;
  86.    hostp->hstats->calls     += remote_stats.calls;
  87.    hostp->hstats->fsent     += remote_stats.fsent;
  88.    hostp->hstats->freceived += remote_stats.freceived;
  89.    hostp->hstats->bsent     += remote_stats.bsent;
  90.    hostp->hstats->breceived += remote_stats.breceived;
  91.    hostp->hstats->errors    += remote_stats.errors;
  92.    hostp->hstats->packets   += remote_stats.packets;
  93.  
  94. } /* dcstats */
  95.  
  96. /*--------------------------------------------------------------------*/
  97. /*    d c u p d a t e                                                 */
  98. /*                                                                    */
  99. /*    Update the status of all known hosts                            */
  100. /*--------------------------------------------------------------------*/
  101.  
  102. void dcupdate( void )
  103. {
  104.    boolean firsthost = TRUE;
  105.    struct HostTable *host;
  106.    FILE *stream;
  107.    size_t len1 = strlen(compilep );
  108.    size_t len2 = strlen(compilev );
  109.  
  110.    if ((stream  = FOPEN(DCSTATUS, "w", BINARY)) == NULL)
  111.       return;
  112.  
  113.    fwrite( &len1, sizeof len1, 1, stream );
  114.    fwrite( &len2, sizeof len2, 1, stream );
  115.    fwrite( compilep , 1, len1, stream);
  116.    fwrite( compilev , 1, len2, stream);
  117.    fwrite( &start_stats , sizeof start_stats , 1,  stream);
  118.  
  119.    while  ((host = nexthost( firsthost , aliasof )) != BADHOST)
  120.    {
  121.       len1 = strlen( host->hostname );
  122.       len2 = sizeof *(host->hstats);
  123.  
  124.       firsthost = FALSE;
  125.  
  126.       fwrite( &len1, sizeof len1, 1, stream );
  127.       fwrite( &len2, sizeof len2, 1, stream );
  128.       fwrite( host->hostname , sizeof hostp->hostname[0], len1, stream);
  129.       host->hstats->save_hstatus = host->hstatus;
  130.       fwrite( host->hstats , len2, 1,  stream);
  131.       memset( host->hstats , '\0', len2); /* Clear totals            */
  132.    }
  133.  
  134. /*--------------------------------------------------------------------*/
  135. /*         Make we sure got end of file and not an I/O error          */
  136. /*--------------------------------------------------------------------*/
  137.  
  138.    if (ferror( stream ))
  139.    {
  140.       printerr( DCSTATUS );
  141.       clearerr( stream );
  142.    }
  143.    fclose( stream );
  144.  
  145. } /* dcupdate */
  146.